package com.fzsf.drawingboard.utils;

import android.graphics.Bitmap;
import android.graphics.Paint;

import com.fzsf.drawingboard.bean.SerializablePath;

import java.util.ArrayList;
import java.util.LinkedList;

/**
 * Created by Taijl on 2018/3/23.
 * 多字手写绘板的相关功类
 */

public class MultiWritingBoardUtils {
    /**
     * 保存图片
     */
    public static void saveImages(int imageW, int imageH, Paint paint, LinkedList<SerializablePath> paths) {
        Bitmap.createBitmap(imageW, imageH, Bitmap.Config.ARGB_8888);
    }

    /**
     * 获取书写字的用于灵云OCR识别的轨迹
     */
    public static short[] getStrokes(LinkedList<SerializablePath> paths) {
        ArrayList<Short> strokes = new ArrayList<>();
        if (null != paths && !paths.isEmpty()) {
            for (int i = 0; i < paths.size(); i++) {
                SerializablePath path = paths.get(i);
                ArrayList<float[]> pathPoints = path.getPathPoints();
                if (pathPoints.isEmpty()) {
                    continue;
                }
                for (float[] fs : pathPoints) {
                    strokes.add((short) fs[0]);
                    strokes.add((short) fs[1]);
                }
                strokes.add((short) -1);
                strokes.add((short) 0);
            }
            strokes.add((short) -1);
            strokes.add((short) -1);
        } else {
            return new short[]{};
        }
        if (!strokes.isEmpty()) {
            Short[] Shorts = new Short[strokes.size()];
            strokes.toArray(Shorts);
            short[] shorts1 = new short[strokes.size()];
            for (int i = 0; i < Shorts.length; i++) {
                shorts1[i] = Shorts[i].shortValue();
            }
            return shorts1;
        } else {
            return new short[]{};
        }
    }
}
